package com;


import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONArray;
import scutiger.provider.GlobalException;
import scutiger.util.LEIClassLoader;
import scutiger.util.YmlUtil;

import java.lang.reflect.Method;
import java.lang.reflect.ParameterizedType;
import java.lang.reflect.Type;
import java.util.ArrayList;
import java.util.List;

/**
 * @author LEI
 * Created by LEI on 2020/5/7.
 */
public class test {
    public static void main(String[] args) throws IllegalAccessException, InstantiationException, ClassNotFoundException {
        //System.out.println("JDdd".toLowerCase());
      /*  String url = "/balancePayTask/list/test/test/test";
        String [] all = "/balancePayTask/list/test/test/test".split("/");
        for (String s : all) {
            System.out.println("-->:"+s);
        }
        System.out.println(url.replaceFirst("/",""));

        Map<String, LBean> classControllers = new ConcurrentHashMap<>();
        classControllers.put("test",new LBean());
        sout

        classControllers.keySet().forEach(System.out::println);*/
//        String controllers = url.substring(0,url.indexOf("/")).trim().length() <=0 ? url.substring(0,url.indexOf("/")):"";
//        System.out.println(controllers);

//        int i = 10;
//
//        for (int i1 = 0; i1 < i; i1++) {
//            System.out.println(i1);
//        }
//        System.out.println("---------------");
//        for (int i1 = 0; i1 < i; ++i1) {
//            System.out.println(i1);
//        }
//         Observer observer = new one();
//         observer.exception();
//
//        Class service = Observer.class;
//        ServiceLoader serviceLoader = ServiceLoader.load(service);
//        Iterator iterator = serviceLoader.iterator();
//        while (iterator.hasNext()){
//            Object next = iterator.next();
//            Observer observer1 = (Observer)next;
//            observer1.exception();
//        }
//        Exception e = new RuntimeException("test");
//        Class<GlobalException> globalExceptionClass = GlobalException.class;
//        GlobalException globalException = LEIClassLoader.load(globalExceptionClass,new SimpleGlobalException());
//        globalException.exception(e);
//        ServiceLoader<GlobalException> load = ServiceLoader.load(GlobalException.class);
//        Iterator<GlobalException> iterator = load.iterator();
//        while (iterator.hasNext()){
//            GlobalException next = iterator.next();
//            System.out.println(next.getClass().getSimpleName());
//        }

//        List<Class> classByPackages = LEIClassLoader.getClassByPackages(GlobalException.class, new SimpleGlobalException(), new String[]{"scutiger.provider"});
//        for (Class classByPackage : classByPackages) {
//            GlobalException globalException = (GlobalException) classByPackage.newInstance();
//            globalException.exception(null);
//        }
//        Object yml = YmlUtil.getYml("class.reflect");
//        System.out.println(yml);
//        System.out.println(yml.toString().split(",")[0]);

        List<hh> hhs = new ArrayList<>();
        hh hh = new hh();
        hh.setName("test");
        hhs.add(hh);

        String string = JSON.toJSONString(hhs);
        System.out.println(string);
        byte[] bytes = string.getBytes();
        String json = new String(bytes);


//        Class<?> class= Class.forName("");

        Method[] methods = Tt.class.getDeclaredMethods();
        Method method = methods[0];
        Type[] genericParameterTypes = method.getGenericParameterTypes();
        Type genericParameterType = genericParameterTypes[0];
        Type genericType = ((ParameterizedType) genericParameterType).getActualTypeArguments()[0];
        String typeName = genericType.getTypeName();
        System.out.println(typeName);

        Class<?> clazz= Class.forName(typeName);
        JSONArray jsonArray = JSON.parseArray(json);
        for (Object o : jsonArray) {
            JSON.toJavaObject(jsonArray.getJSONObject(0),clazz);
        }
//        List list = JSON.parseObject(json, clazz);
//        System.out.println(list);
    }

    static class Tt{
        public void test(List<hh> hhs,String ss){
            System.out.println(hhs);
        }
    }

    static class hh{
       private String name;

        public void setName(String name) {
            this.name = name;
        }

        public String getName() {
            return name;
        }
    }

}
